package io.renren.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.dao.AppDao;
import io.renren.dao.AppDataDao;
import io.renren.entity.App;
import io.renren.entity.AppData;
import io.renren.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("appService")
public class AppServiceImpl extends ServiceImpl<AppDao, App> implements AppService {

    @Autowired
    private AppDataDao appDataDao;

    @Override
    public PageUtils queryPage( Map<String, Object> params ) {
        EntityWrapper<App> wrapper = new EntityWrapper<>();
        wrapper.eq("is_deleted", 0 );
        wrapper.eq( "is_self", 0 );
        wrapper.orderBy("sort" );
        Page<App> page = this.selectPage(
                new Query<App>(params).getPage(),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public App queryAppDetail( Integer appId ) {
        App app = this.selectById( appId );
        if( app == null ){
            return new App();
        }
        AppData appData = appDataDao.selectById( appId );
        app.setAppData( appData );
        return app;
    }
}
